<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8"/>
    <title>编辑配送信息</title>
    <script type="text/javascript" src="/js/jquery-1.11.1.js"></script>
    <script type="text/javascript" src="/js/bootstrap.js"></script>
    <link rel="stylesheet" type="text/css" href="/css/bootstrap.css"/>
    <link rel="stylesheet" type="text/css" href="/css/style.css"/>
    <style>
        label span {
            color: #ff0000;
            padding-right: 5px;
        }
    </style>
</head>

<body>
<h2>编辑配送信息</h2>
<form id="myForm" class="form-horizontal" method="post">
    <input type="hidden" name="in_num">
    <div class="form-group">
        <label class="col-sm-1 control-label"><span>*</span>订单编号</label>
        <div class="col-sm-9">
            <input name="o_id" required="required" class="form-control" placeholder=""/>
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-1 control-label"><span>*</span>客户名称</label>
        <div class="col-sm-9">
            <input name="c_name" class="form-control" placeholder=""/>
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-1 control-label">应收额数</label>
        <div class="col-sm-9">
            <input name="d_money" class="form-control" placeholder=""/>
        </div>
    </div>

    <!--时间-->
    <div class="form-group">
        <label class="col-sm-1 control-label">配送时间</label>
        <div class="col-sm-5">
            <input name="d_time" class="form-control" type="datetime-local"/>
        </div>
    </div>

    <div class="form-group">
        <label class="col-sm-1 control-label">备注</label>
        <div class="col-sm-9">
            <input name="d_remarks" class="form-control"/>
        </div>
    </div>

    <div class="form-group">
        <label class="col-sm-1 control-label"></label>
        <div class="col-sm-9">
            <button id="btnUpdate" type="button" class="btn btn-sm btn-info">提&nbsp;交</button>
        </div>
    </div>

</form>

</body>
</html>
<script>

    String.prototype.GetValue = function (para) {
        let reg = new RegExp("(^|&)" + para + "=([^&]*)(&|$)");
        let r = this.substr(this.indexOf("\?") + 1).match(reg);
        if (r != null) return unescape(r[2]);
        return null;
    }
    $(function () {
        let url = document.location.toString();
        let d_num = url.GetValue("d_num");
        loadData(d_num);
        //提交按钮的单击事件
        $("#btnUpdate").click(function () {
            $.ajax({
                type: "POST",
                url: "/distribution",
                data: $("#myForm").serialize() +'&d_num='+d_num+'&_method=PUT',
                dataType: "json",
                success: function (vo) {
                    if (vo.code == 200) {
                        alert("操作成功！");
                        window.location.href = "/pages/distribution/list.html";
                    } else {
                        alert("更改失败！" + vo.msg);
                    }
                }
            });
        });

    });

    function loadData(d_num) {
        $.ajax({
            type: "GET",
            url: "/distribution/" + d_num,
            data: "",
            success: function (vo) {
                let obj = vo.obj;
                $("input[name='o_id']").val(obj.o_id);
                $("input[name='c_name']").val(obj.c_name);
                $("input[name='d_money']").val(obj.d_money);
                $("input[name='d_time']").val(obj.d_time);
                $("input[name='d_remarks']").val(obj.d_remarks);
            }
        });
    }
</script>